import { defHttp } from '/@/utils/http/axios';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryProductAssistantUnitVo } from '@/api/base-data/product/unit/model/queryProductAssistantUnitVo';
import { QueryProductAssistantUnitBo } from '@/api/base-data/product/unit/model/queryProductAssistantUnitBo';
import { GetProductAssistantUnitBo } from '@/api/base-data/product/unit/model/getProductAssistantUnitBo';
import { ProductAssistantUnitVo } from '@/api/base-data/product/unit/model/productAssistantUnitVo';

const baseUrl = '/basedata/product/assistant/unit';
const region = 'cloud-api';

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryProductAssistantUnitVo): Promise<QueryProductAssistantUnitBo[]> {
  return defHttp.get<QueryProductAssistantUnitBo[]>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetProductAssistantUnitBo> {
  return defHttp.get<GetProductAssistantUnitBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param productId
 * @param params
 * @returns {Promise}
 */
export function save(productId: string, params: ProductAssistantUnitVo[]): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl + '/' + productId,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}
